package com.atguigu.lease.web.app.custom.config;

import com.atguigu.lease.web.app.custom.convert.StringToBaseEnumsConverterFactory;
import com.atguigu.lease.web.app.intecepter.AuthenticationIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@PropertySource("classpath:application.yml")
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
    @Autowired
    private StringToBaseEnumsConverterFactory stringToBaseEnumsConverterFactory;
    @Autowired
    private AuthenticationIntercepter authenticationIntercepter;
    @Value("${app.auth.path-patterns.include}")
    private String addPathPatterns;
    @Value("${app.auth.path-patterns.exclude}")
    private String excludePathPatterns;
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(stringToBaseEnumsConverterFactory);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationIntercepter)
                .addPathPatterns(addPathPatterns)
                .excludePathPatterns(excludePathPatterns)
                .excludePathPatterns("/doc.html");
    }
}
